#include <iostream>

#include "gtest/gtest.h"

#include "Utility/FileSystem/SGFileSystem.h"

#include "DataStructure/Input/Load/RLOAD2Data.h"

#include "SGFem/Task/Common/DynamicLoad.h"
#include "SGFem/Task/Kernel/MModel.h"

extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;

using SG::DataStructure::FEM::RLOAD2Data;
using SG::Import::SGImporter;

class RLOAD2_LSEQ_Ref_PLOAD4_Test : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
        
        const auto fileName = SG::Utility::FileSystem::getTestDataPath ("SGFem/Task/DynaLoad/") + "RLOAD2_LSEQ_Ref_PLOAD4.bdf";
        SGImporter import (DB_SERVICEFACTORY);
        import.Import (fileName);

        Kernel::MModel modal (SOLType::SOL_SEDFREQ, DB_SERVICEFACTORY);

        modal.Initialize ({ 1 });
        modal.CalcMatrixEquation (1);
    }

    Id caseLoadSetId = 10;
};

// 测试数据太简单，考虑重写
// TEST_F (RLOAD2_LSEQ_Ref_PLOAD4_Test, ShouldResolveStaticLoadAndComputeVector)
// {
//     RLOAD2Data rload2_data;
//     rload2_data.m_sId   = 5;
//     rload2_data.m_DAREA = 12;
//     rload2_data.m_TB    = 6;

//     auto loadSidSet = getStaticLoadId (rload2_data, DB_SERVICEFACTORY, caseLoadSetId);
//     ASSERT_EQ (loadSidSet[0], 101);

//     RLoad2Calc loadCalc (rload2_data, caseLoadSetId, 1.0);
//     ASSERT_EQ (loadCalc.computeA (DB_SERVICEFACTORY, 1), SG::DataStructure::Common::Status::STATUS_Success);

//     const auto& fStatic = loadCalc.getStaticForce ();

//     SG::Algebra::Vec_t fStatic_target (fStatic.size ());
//     fStatic_target << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.625, 0, 0, 0, 0, 0,
//         0.625, 0, 0, 0, 0, 0, 0.625, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.625, 0, 0, 0;

//     ASSERT_TRUE (fStatic.isApprox (fStatic_target, TOLERANCE));
// }

// TEST_F (RLOAD2_LSEQ_Ref_PLOAD4_Test, ShouldInterpolateForceCorrectlyAtGivenFrequency)
// {
//     RLOAD2Data rload2_data;
//     rload2_data.m_sId   = 5;
//     rload2_data.m_DAREA = 12;
//     rload2_data.m_TB    = 6;

//     RLoad2Calc loadCalc (rload2_data, caseLoadSetId, 2.0);

//     loadCalc.computeA (DB_SERVICEFACTORY, 1);

//     SG::Algebra::Vec_t p_f_5  = loadCalc.Interplate (DB_SERVICEFACTORY, 5.0);
//     SG::Algebra::Vec_t p_f_10 = loadCalc.Interplate (DB_SERVICEFACTORY, 10.0);

//     SG::Algebra::Vec_t p_f_5_target (p_f_5.size ());
//     p_f_5_target << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.625, 0, 0, 0, 0, 0, 0.625,
//         0, 0, 0, 0, 0, 0.625, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.625, 0, 0, 0;
//     ASSERT_TRUE (p_f_5.isApprox (p_f_5_target, TOLERANCE));

//     SG::Algebra::Vec_t p_f_10_target (p_f_10.size ());
//     p_f_10_target << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.25, 0, 0, 0, 0, 0, 1.25, 0,
//         0, 0, 0, 0, 1.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.25, 0, 0, 0;
//     ASSERT_TRUE (p_f_10.isApprox (p_f_10_target, TOLERANCE));
// }